<template>
	<div>
		<el-form ref="form" :model="form" label-width="100px">

		<!-- 	<el-form-item label="序号" prop="nId">
				<el-input v-model="form.nId"></el-input>
			</el-form-item> -->
			<el-form-item label="员工姓名" prop="staffName">
				<el-input v-model="form.staffName"></el-input>
			</el-form-item>
			<el-form-item label="性别" prop="staffSex">
				<el-select v-model="form.staffSex">
					<el-option v-for="(item,index) in sexData" :key="index" :value="item.value" :label="item.label"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="员工年龄" prop="staffAge">
				<el-input v-model="form.staffAge"></el-input>
			</el-form-item>
			<el-form-item label="员工号" prop="staffId">
				<el-input v-model="form.staffId"></el-input>
			</el-form-item>
			<el-form-item label="员工类别" prop="staffSort">
				<el-select v-model="form.staffSort" placeholder="请选择状态" clearable :style="{width: '100%'}">
					<el-option v-for="(item, index) in stateOptions" :key="index" :label="item.label"
						:value="item.value" :disabled="item.disabled"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="入职时间" prop="entryTime">
				<el-date-picker v-model="form.entryTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
					:style="{width: '100%'}" placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="创建时间" prop="createTime">
				<el-date-picker v-model="form.createTime" format="yyyy-MM-dd HH:mm:ss"
					value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}" placeholder="请输入时间" clearable>
				</el-date-picker>
			</el-form-item>
			<el-form-item label="职务" prop="staffPost">
				<el-input v-model="form.staffPost"></el-input>
			</el-form-item>
			<el-form-item label="人员状态" prop="staffState">
				<el-select v-model="form.staffState" placeholder="请选择状态" clearable :style="{width: '100%'}">
					<el-option v-for="(item, index) in stateData" :key="index" :label="item.label"
						:value="item.value" :disabled="item.disabled"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="简介" prop="introductory">
				<el-input v-model="form.introductory"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	export default {
		name: 'staffManagementEdit',
		components: {

		},
		props: [
			'showEdit',
			'nid',
			'editid'
		],
		data() {
			return {
				stateOptions: [{
					"label": "护工",
					"value": "护工"
				}, {
					"label": "医生",
					"value": "医生"
				}, {
					"label": "护士",
					"value": "护士"
				}, {
					"label": "健康管家",
					"value": "健康管家"
				}],
				stateData:[{
					"label": "在职",
					"value": "在职"
				},{
					"label": "离职",
					"value": "离职"
				}],
				form: {
					nId: '',
					staffName: '',
					staffSex: '',
					staffAge: '',
					staffId: '',
					staffSort: '',
					entryTime: '',
					createTime: '',
					staffPost: '',
					staffState: '',
					introductory: ''
				},
				sexData: [{
				     "label": "男",
				     "value": "男"
				    }, {
				     "label": "女",
				     "value": "女"
				    }],
				url: '/staffManagement/save',
				depts: [],
			}
		},
		created() {
			console.log("this.editid:" + this.editid)
			if (this.editid) {

				this.axios.get('/staffManagement/toedit', response => {
					this.form.nId = response.obj.nid
					this.form.staffName = response.obj.staffName
					this.form.staffSex = response.obj.staffSex
					this.form.staffAge = response.obj.staffAge
					this.form.staffId = response.obj.staffId
					this.form.staffSort = response.obj.staffSort
					this.form.entryTime = response.obj.entryTime
					this.form.createTime = response.obj.createTime
					this.form.staffPost = response.obj.staffPost
					this.form.staffState = response.obj.staffState
					this.form.introductory = response.obj.introductory
				}, {
					nId: this.editid
				})
			}
		},
		methods: {
			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			}

		}
	}
</script>

<style>
</style>
